package com.minelx.sequence.pattern;

import com.minelx.sequence.core.RepeatMatcher;
import com.minelx.sequence.core.ReturnMatcher;
import com.minelx.sequence.core.StringScanner;

import java.util.stream.Collectors;

import static java.util.stream.Collectors.joining;

public class RepeatPatternMatcher implements ReturnMatcher<ReturnMatcher<?, StringScanner>, StringScanner> {
	private final ReturnMatcher<?, StringScanner> repeated;

	public RepeatPatternMatcher(ReturnMatcher<?, StringScanner> repeated) {
		this.repeated = repeated;
	}

	@Override
	public boolean isMatch(StringScanner clue) {
		return clue.exists("+");
	}

	@Override
	public ReturnMatcher<?, StringScanner> onMatched(StringScanner clue) {
		clue.goes("+");
		return new RepeatMatcher<>(repeated);
	}
}
